import './index.less'
import 'array.prototype.at/auto'
import './utils/structuredClone'
// import { loadPDFJS } from './config'
import PDFViewApp from './PDFViewApp'
// http://local.petslib.cn:5173/?file=https://oss.petslib.cn/prod/static/temp/bad4557493595e910cccb6a2b206a8c6.pdf&page=10
// https://test.petslib.cn/pdfviewer/index.html?file=https://oss.petslib.cn/prod/static/pc/pdf/3390869.pdf&page=2
const start = () => {
    const search = new URLSearchParams(location.search)
    const url = search.get('file')
    const page = +search.get('page')
    if (!url) {
        console.log('url is required')
        return
    }
    const container = document.getElementById('pdfviewer-wrapper')
    const app = new PDFViewApp(container)
    const opts = {
        url: decodeURIComponent(url),
        //  url: 'https://oss.petslib.cn/prod/static/pc/pdf/3390869.pdf',
        //  url: '/巨量算数2022抖音宠物行业年中复盘报告7页.pdf',
        //  url: '/cc960b25b231bdbe047bcf786045f64a.pdf',
        //  page: 2
    }
    if (page) {
        opts.page = page
    }
    app.start(opts)
}

document.addEventListener('DOMContentLoaded', () => {
    if (IS_MOBILE) {
        document.body.classList.add('isMobile')
    }
    start()
    // loadPDFJS().then(() => start())
})

document.addEventListener("DOMContentLoaded", function () {
    const createWatermark = () => {
        const id = 'watermarkWrapper'
        if(document.getElementById(id)) {
            document.getElementById(id).remove()
        }
        const dv = document.createElement('div')
        dv.id = id
        dv.className = id
        document.body.appendChild(dv)
    }
    createWatermark()
})